package club.zhcs.sbc;

import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.context.request.async.DeferredResult;

import club.zhcs.sbc.util.MyMapper;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 环境感知参考https://www.tianmaying.com/tutorial/deploy-spring-boot-application
 * 
 * @author guiyuan.wang-N
 *
 *         createTime 2016年12月29日下午5:09:25
 *
 */
@SpringBootApplication
@EnableAutoConfiguration
@ServletComponentScan
@EnableSwagger2
@MapperScan(basePackages = "club.zhcs.sbc.mapper", markerInterface = MyMapper.class)
public class Application extends SpringBootServletInitializer {

	public static void main(String[] args) {
		SpringApplication application = new SpringApplication(Application.class);
		application.run(args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(Application.class);
	}

	@Bean
	public Docket swaggerSpringMvcPlugin() {
		ApiInfo apiInfo = new ApiInfo("Spring-boot-camunda", "rest apis", "1.0", "https://github.com/Kerbores", "kerbores@gmail.com", "Apache Licence 2.0",
				"http://www.apache.org/licenses/LICENSE-2.0.html");
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("api")
				.genericModelSubstitutes(DeferredResult.class)
				.useDefaultResponseMessages(false)
				.forCodeGeneration(true)
				.pathMapping("/")
				.select()
				.paths(or(regex(".*")))
				.build()
				.apiInfo(apiInfo);
	}

}
